package com.bdqn.service.impl;



import com.bdqn.mapper.SysRoleMapper;
import com.bdqn.pojo.SysRole;
import com.bdqn.pojo.SysUser;
import com.bdqn.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * SysUserServiceImpl
 *
 * @aurhor Administrator  whs
 * @since 2024/7/19
 */

@Transactional // 为该类的所有业务方法统一添加事务处理
@Service("SysRoleServiceImpl")
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired  //@ Resource
    private SysRoleMapper sysRoleMapper;

    public SysRoleMapper getSysRoleMapper() {
        return sysRoleMapper;
    }

    public void setSysRoleMapper(SysRoleMapper sysRoleMapper) {
        this.sysRoleMapper = sysRoleMapper;
    }


    @Transactional(propagation = Propagation.SUPPORTS)


    /**
     * 根据 角色名称 模糊查询角色信息列表的操作，并进行 分页查询
     *
     * @param roleName
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @Override
    public List<SysRole> selectSysRolePageBeginRoleNameLimitList(String roleName, Integer pageIndex, Integer pageSize) {
        return sysRoleMapper.selectSysRolePageBeginRoleNameLimitList(roleName, pageIndex, pageSize);
    }

    /**
     * 统计总数据
     *
     * @param roleName
     * @return
     */
    @Override
    public int count(String roleName) {
        return sysRoleMapper.count(roleName);
    }

    /**
     * 实现角色信息的添加操作
     *
     * @param sysRole
     * @return
     */
    @Override
    public boolean addSysRole(SysRole sysRole) {
        return sysRoleMapper.addSysRole(sysRole);
    }

    /**
     * 根据用户id查询角色的详情信息
     *
     * @param id
     * @return
     */
    @Override
    public SysRole getUserById(Integer id) {
        return sysRoleMapper.getUserById(id);
    }


    /**
     * 根据角色id修改角色信息
     * @param sysRole
     * @return
     */
    @Override
    public boolean updateSysRoleId(SysRole sysRole) {
        return sysRoleMapper.updateSysRoleId(sysRole) == 1 ;
    }

    /**
     * ch08简答2
     * 根据用户角色id 查询用户表中是否有相关的数据信息
     *
     * @param roleId 户角色id
     * @return
     */
    @Override
    public List<SysUser> selectSysUserOnRoleId(Integer roleId) {
        return sysRoleMapper.selectSysUserOnRoleId(roleId);
    }


    /**
     * ch08 简答3
     * 根据角色id 去用户表中查询 用户表中 有没有角色id的相关信息 如果没有则直接删除角色表信息
     *
     * @param id 角色id
     * @return
     */
    @Override
    public int deleteSysRoleOnRoleId(Integer id) {
            return sysRoleMapper.deleteSysRoleOnRoleId(id);
    }

    /**
     * 查询角色信息列表
     * @return
     */
    @Override
    public List<SysRole> list() {
        return sysRoleMapper.list();
    }
}
